﻿using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Collections;
using System.Text;
using System.IO;
using System.Data;
using System.Configuration;
using SSRS;
using PHSRAG.Insight21.Reports;
using PHSRAG.Insight21.Context;

namespace PHSRAG.Insight21.Agreements.Reports
{
    /// <remarks>Class for generating Advance Fund Request report</remarks>
    public class sqlAdvanceFundRequest : sqlReport
    {
        private const string SortKey = "AdvanceFundRequestLandingSortKey_27F443FA-B77C-4ced-81B0-2099CD9A586E";
        private const string SortDirection = "AdvanceFundRequestLandingSortDirection_B6836CCD-FA0B-4690-A0FC-52352E590F6C";

        public sqlAdvanceFundRequest(string pageUrl)
            : base(pageUrl)
        {
            doCustomExcelReport = false;
        }
                
        public override ParameterValue[] setParameters(ref string rptName)
        {
            ArrayList reportParams = new ArrayList();
            string SortField = "";
            string SortDir = "";
            string FilterCriteria = "";

            ParameterValue paramValue = new ParameterValue();
            paramValue.Name = "fwkDomainUserId";
            paramValue.Value = ((UserContext)cachePolicy.GetCachedObject(UserContext.CacheKey)).DomainUserId.ToString();
            reportParams.Add(paramValue);

            Hashtable h = pageCachePolicy.GetCachedObject(Keys.AdvanceFundRequestLandingPageKey) as Hashtable;
            SortField = (h == null || h[SortKey] == null) ? "" : h[SortKey].ToString();
            SortDir = (h == null || h[SortDirection] == null) ? "" : h[SortDirection].ToString();
            SortField = SortField + " " + SortDir;

            paramValue = new ParameterValue();
            paramValue.Name = "OrderBy";
            paramValue.Value = SortField;
            reportParams.Add(paramValue);

            paramValue = new ParameterValue();
            paramValue.Name = "PageSize";
            paramValue.Value = "0";
            reportParams.Add(paramValue);

            paramValue = new ParameterValue();
            paramValue.Name = "PageStartIndex";
            paramValue.Value = "0";
            reportParams.Add(paramValue);

            paramValue = new ParameterValue();
            paramValue.Name = "PageEndIndex";
            paramValue.Value = "1";
            reportParams.Add(paramValue);

            paramValue = new ParameterValue();
            paramValue.Name = "username";
            paramValue.Value = ((UserContext)cachePolicy.GetCachedObject(UserContext.CacheKey)).FirstName.ToString() + " " + ((UserContext)cachePolicy.GetCachedObject(UserContext.CacheKey)).LastName.ToString();
            reportParams.Add(paramValue);

            ParameterValue[] oInputPrms = (ParameterValue[])reportParams.ToArray(typeof(ParameterValue));

            return oInputPrms;
        }
    }
}
